var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    pintuanList: [],
    status: 0,
    typename: '拼团中',
    page: 1,
    limit: 10
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    this.getPintuanList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getPintuanList: function () {
    let that = this;
    util.request(api.MyPintuanList, {
      status: that.data.status,
      page: that.data.page,
      limit: that.data.limit
    }).then(function (res) {
      if (res.result == 1) {
        if (res.data.length > 0) {
          that.setData({
            pintuanList: that.data.pintuanList.concat(res.data),
          });
        } else {
          if (that.data.pintuanList.length > 0) {
            wx.showToast({
              title: '已经被您看完了!',
              icon: 'none',
              duration: 2000
            });
            return false;
          }
        }
      }

    });
  },

  switchTab: function (e) {
    let that = this;
    var status = e.currentTarget.dataset.status;
    that.setData({
      pintuanList: [],
      status: status,
      page: 1,
      size: 10,
      scrollTop: 0
    });
    if (status == 0) {
      this.setData({
        typename: '拼团中'
      });
    }
    if (status == 1) {
      this.setData({
        typename: '拼团成功'
      });
    }
    if (status == 2) {
      this.setData({
        typename: '拼团失败'
      });
    }
    that.getPintuanList();
  },
  /**
   * 去逛逛
   */
  goPages: function () {
    wx.navigateTo({
      url: "/pages/marketing/pintuan/pintuanList/pintuanList"
    });
  },
})